<?php 
//---------- config
$manager="TH&#212;NG TIN LI&#202;N H&#7878;";// tieu de trang

$par_page		="sr_contact";// vi tri trang hien thi trong site
$item           ="contact";
$id_item        ="id_contact";

$itemname 		="th&#244;ng tin li&#234;n h&#7879;";

if($_GET['p'])
{
	$p=intval($_GET['p']);
	if($p==0){
		$p=1;
	}
}else {
	$p=1;
}
$id=intval($_GET['id']);
$tpl=new TemplatePower("skin/sk_contact.htm");
$tpl->prepare();
$tpl->assignGlobal("categoryname",$categoryname);
$tpl->assignGlobal("p",$p);
$tpl->assignGlobal("manager",$manager);
$tpl->assignGlobal("itemname",$itemname);
$tpl->assignGlobal("par_page",$par_page);
$navigator=" <a href='?page=".$par_page."&code=00' class='link_name'>Root></a>";
// show list
if(!$_GET['code'] || $_GET['code']=='00'){
	showlist();
}
// view detail
if($_GET['code']=='01'){
	if($id){
		$sql="SELECT * FROM ".$item." WHERE ".$id_item."=".$id;
		$db=$DB->query($sql);
		if($rs=mysql_fetch_array($db)){
			$tpl->newBlock("view_detail");
			$tpl->assign("name",$rs['name']);
			$tpl->assign("id",$id);
			$tpl->assign("content",$rs['content']);
			$DB->query("UPDATE ".$item." SET xem=1 WHERE ".$id_item."=".$id);
		}
	}
	showlist();
}
if($_GET['code']=='02'){
	$sql="DELETE FROM ".$item." WHERE ".$id_item."=".$id;
	$DB->query($sql);
	message("&#272;&#227; x&#243;a xong !");
	showlist();
}
function showlist(){
	global $DB,$tpl,$item,$maxpage,$maxitem,$id_item,$par_page;
	$sql="SELECT * FROM ".$item." ORDER BY ".$id_item." DESC";
	$d=$DB->query($sql);
	$count=mysql_num_rows($d);
	$tpl->assignGlobal("count",$count);
	$db=phan_trang($_GET['p'],"?page=".$par_page."&code=00",$sql,$maxpage,$maxitem,'p');
	$tt=0;
	$i=0;
	while($rs=mysql_fetch_array($db['db'])){
		$tt++;
		$tpl->newBlock("list");
		$tpl->assign("id",$rs['id_contact']);
		if($rs['xem']==1){
			$tpl->assign("name",$rs['name']);
		}else {
			$tpl->assign("name","<strong>".$rs['name']."</strong>");
		}
		$tpl->assign("stt",$tt);
		$i++;
		if($i==2){
			$tpl->assign("cl","bg_row_list");
			$i=0;
		}else {
			$tpl->assign("cl","");
		}
	}
	if($tt<=0){
		$tpl->newBlock("thongbao");
		$tpl->assign("thongbao","Ch&#432;a c&#243; th&#244;ng tin !");
	}
	$tpl->newBlock("cac_trang");
	$tpl->assign("cac_trang",$db['cac_trang']);
}
$tpl->printToScreen();
?>